package cn.edu.jxau.test;

import java.io.IOException;
import java.util.Arrays;

/**
 * 冒泡排序
 * @author 付大石
 */
public class Sort {

    public static void main(String[] args) throws IOException {

        int[] arr = { 23, 54, 86, 23, 87, 12, 80, 43, 65 };
        sort(arr);
        System.out.println(Arrays.toString(arr));
    }

    private static void sort(int[] arr) {

        boolean isSorted = false;
        for (int i = 0; i < arr.length && !isSorted ; i++) {
            isSorted = true;
            for (int j = 0; j < arr.length - i - 1; j++) {
                if (arr[j] > arr[j + 1]) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                    isSorted = false;
                }
            }
        }
        
//        for (int i = 0; i < arr.length ; i++) {
//            for (int j = 0; j < arr.length - i - 1; j++) {
//                if (arr[j] > arr[j + 1]) {
//                    int temp = arr[j];
//                    arr[j] = arr[j + 1];
//                    arr[j + 1] = temp;
//                }
//            }
//        }
    }
}